package logic

import (
	"context"
	"fmt"
	"gorm.io/gorm"
	"house/models/mysql"

	"house/bookingrpc/bookingrpc"
	"house/bookingrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookingDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookingDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookingDelLogic {
	return &BookingDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookingDelLogic) BookingDel(in *bookingrpc.BookingDelRequest) (*bookingrpc.BookingDelResponse, error) {
	// todo: add your logic here and delete this line
	begin := mysql.DB.Begin()
	booking := mysql.BookIng{
		Model:  gorm.Model{ID: uint(in.BookingId)},
		Status: "已取消",
	}
	err := begin.Updates(&booking).Error
	if err != nil {
		begin.Rollback()
		return nil, fmt.Errorf("取消失败")
	}
	begin.Commit()
	return &bookingrpc.BookingDelResponse{}, nil
}
